package com.gsn.engine.utility;

import java.io.File;
import java.util.HashMap;
import java.util.Map;

import javax.security.auth.login.LoginContext;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.math.Vector3;
import com.badlogic.gdx.scenes.scene2d.Group;
import com.badlogic.gdx.scenes.scene2d.Stage;
import com.badlogic.gdx.scenes.scene2d.ui.TextField;
import com.gsn.login.LoginLayer;

public class UtilityDesktop implements IUtility {

	private static final String tag = "UtilityDesktop";

	public UtilityDesktop() {

	}

	@Override
	public void setActivity(Object activity) {
		Gdx.app.log(tag, "setActivity");
	}

	@Override
	public void showProgressDialog(String title, String msg) {
		Gdx.app.log(tag, "showProgressDialog : " + title + "| " + msg);

	}

	@Override
	public void hideProgressDialog() {
		Gdx.app.log(tag, "hideProgressDialog ");

	}

	@Override
	public void runOnUiThread(Runnable method) {
	}

	@Override
	public void downloadPictureAsync(String id, String link, int width, int height, String localPath, IPictureDownloadListener listener) {
		File outFile = Gdx.files.internal("tmp/avatar.png").file();
		listener.onFinishLoading(id, outFile);

	}

	@Override
	public void toast(String toast, boolean shortTime) {
		Gdx.app.log(tag, "Toast : " + toast);

	}

	@Override
	public void showInputTextDlg(String inText, String outDefaultText, IInputText listener) {
		// TODO Auto-generated method stub

	}

	private Map<String, TextField> mapTextField = new HashMap<String, TextField>();

	// makeTextFieldWithStageCoordinate
	@Override
	public void makeTextFieldWithScreenCoordinate(Stage stage, TextField.TextFieldStyle style, String type, String content, float wide, float height, float marginTop, float marginLeft) {
		TextField field = new TextField(content, style);
		mapTextField.put(type, field);
		field.width = wide;
		field.height = height;
		field.x = marginLeft;
		field.y = Gdx.graphics.getHeight() - marginTop - height;

		stage.addActor(field);

	}

	@Override
	public void hideTextField(String type) {
		// TODO Auto-generated method stub
		TextField textField = mapTextField.get(type);
		if (textField != null)
			textField.visible = false;
	}

	@Override
	public String getString(String type) {
		return mapTextField.get(type).getText();
	}

	@Override
	public void visibleTextField(String type) {
		// TODO Auto-generated method stub
		TextField textField = mapTextField.get(type);
		if (textField != null)
			textField.visible = true;

	}

	@Override
	public void setTextField(String type, String content) {
		// TODO Auto-generated method stub
		TextField textField = mapTextField.get(type);
		if (textField != null)
			textField.setText(content);
	}

	@Override
	public void save() {
		// TODO Auto-generated method stub

	}

	@Override
	public void saveSetting() {
		// TODO Auto-generated method stub

	}

	@Override
	public void load() {
		// TODO Auto-generated method stub

	}

	@Override
	public void remove() {
		// TODO Auto-generated method stub

	}

	@Override
	public void toastException(String msg, Exception ex) {
		// TODO Auto-generated method stub
		Gdx.app.log(tag, "Toast Exception : ");
		ex.printStackTrace();
	}

	@Override
	public void inviteFriend() {
		// TODO Auto-generated method stub
		Gdx.app.log(tag, "Moi ban");
	}

	@Override
	public void register() {
		// TODO Auto-generated method stub
		Gdx.app.log(tag, "Dang ki");
	}

	@Override
	public void endActivity() {
		// TODO Auto-generated method stub
		System.out.println("end activity ");
	}

}
